package com.aizuda.boot.modules.business.log.controller;

import com.aizuda.boot.modules.business.log.domain.request.ExportLogDTO;
import com.aizuda.boot.modules.business.log.domain.request.LogQueryDTO;
import com.aizuda.boot.modules.business.log.domain.request.LogSaveDTO;
import com.aizuda.boot.modules.business.log.domain.response.LogShowDTO;
import com.aizuda.boot.modules.business.log.service.LogService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * @Author sangyirong
 * @ClassName LogController
 * @Version 1.0
 * @Date 2025/6/5 14:11
 */
@Slf4j
@RestController
@RequestMapping("/log")
@Tag(name = "日志", description = "日志相关接口")
public class LogController {

    @Resource
    private LogService logService;

    @Operation(summary = "获取日志类型")
    @GetMapping("/logType")
    public List<HashMap<String, String>> getLogType() {
        return logService.getLogType();
    }

    @Operation(summary = "获取日志")
    @PostMapping("/getLog")
    public IPage<LogShowDTO> getLogPage(@RequestBody LogQueryDTO logQueryDTO){
        return logService.getLogPage(logQueryDTO);
    }

    @Operation(summary = "保存日志")
    @PostMapping("/saveLog")
    public void saveLog(@RequestBody LogSaveDTO logSaveDTO){
        logService.saveLog(logSaveDTO);
    }

    @Operation(summary = "导出日志文件")
    @PostMapping("/exportLog")
    public void exportLog(@RequestBody ExportLogDTO exportLogDTO, HttpServletResponse response){
        logService.exportLog(exportLogDTO, response);
    }
}
